<include file="Common:header" />
<body>
<table><tr>
<td width="180" valign="top"><include file="Common:adminpanel" /></td>
<td valign="top" >
<div>
	<form id="form1" name="form1" method="post" action="<{:U('templatepricesave')}>">
		<table width="100%" cellspacing="1" cellpadding="3" border="0">
			<tr>
				<td height="30" align="right">地区价格：</td>
				<td>

					<table width="600" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td height="30" align="right" bgcolor="#EEE" colspan="4">
								<div>
									<input type="button" name="button" id="btn_adddqjg" value="添加地区价格" />
								</div>
							</td>
						</tr>
						 <tr><td align="left" bgcolor="#CCCCCC" colspan="4"><div id="pricebox">
						<{$distr}>
						</div></td>
					</table>
				</td>
			</tr>
			<tr>
				<td height="30" align="right">&nbsp;</td>
				<td>
				<input type="submit" name="button2" id="button2" value="提交" />
				<input type="hidden" name="tplid" id="tplid" value="<{$tplid}>" />
				<input type="button" name="button3" id="button3" value="返回列表" onclick="window.location.href='/ThinkPHP3.1.2_Core/TaoApp/index.php?s=/PostSetting/templatelist'" />
				</td>
			</tr>
			<tr>
				<td></td>
				<td height="30"   colspan="2">
				<div style="font-family: 微软雅黑,Tahoma; letter-spacing: 2px; display: block;"  id="result"></div>
				</td>
			</tr>
		</table>
		<br /> <br />
	</form>
	
</div>
</td>
</tr>
</table>
<script> 
$(document).ready(function(){
	
	$("#btn_adddqjg").bind('click', function(){
		
		var n = $("#pricebox");
		var html = '<div>';
			html += ' 到达地区:<select name="did[]"><{:$district}></select>';
			html += ' 起步价:<input name="ptdstartprice[]" type="text" id="qbj" value="10" size="10" />';
			html += ' 加价:<input name="ptdincreaseprice[]" type="text" id="dqjj" value="5" size="10" />'; 
			html += ' <input type="button" name="button" id="btn_delprice" value="删除" />';
			html += '</div>';
		n.append( html );
		
	});
	
	
	$("#btn_delprice").live('click', function(){
		var t = $(this);
		t.parent("div").remove();
	} );
	
	
	$("#btn_delprice2").live('click', function(){
		var t = $(this);
		var id = t.attr("alt");
		if( confirm( '确定删除已有城市吗？' )) {
			$.post("<{:U('templatepricedel')}>", 
					{ id: id , tplid: <{$tplid}>  }, 
					function(data){  
						if( 1== data.status ){
							$('#result').html(data.info).show().fadeOut(2000);
							setTimeout( function() {
								t.parent("div").remove(); 
							} , 500 );
						}else{
							alert( data.info );
							return false;
						}
					},
				'json'
			);
			
		}
		
		
	});
	
	// FROM  Submit 
	
	$('#form1').ajaxForm({
        beforeSubmit:  checkForm,  // pre-submit callback
        success:       complete,  // post-submit callback
        dataType: 'json'
    });
    function checkForm(){
    	/*
        if( '' == $.trim($('#title').val())){
            $('#result').html('标题不能为空').show();
            return false;
        }
    	*/
        //可以在此添加其它判断
    }
    function complete(data){
        if (data.status==1){
            $('#result').html(data.info).show().fadeOut(2000);            
        }else{
            $('#result').html(data.info).show();
        }
    }
			
});

</script>
</body>
</html>